<?php

class sys_log_viewer extends a_front_controller {

    public function __construct() {
        if(!has_debug_permission ()){
            show_error("Your IP is not allowed");
            exit();
        }
        parent::__construct(FALSE);
        $this->load->library("json");

    }

    
    public function index() {
        
    }

    public function batch_assign() {
        $this->assign("modules", Module_Extended::list_modules());
    }

    /**
     * @internal
     */
    public function do_partial_rendering() {
        return TRUE;
    }

    public function get_data() {
        $start_index = $_POST['iDisplayStart'];
        $num_records = $_POST['iDisplayLength'];
        $criteria = array();
        if ($this->input->post('module_name') && strlen($this->input->post('module_name'))) {
            $criteria['where']['module_name'] = $this->input->post('module_name');
        }
        if ($this->input->post('type') && strlen($this->input->post('type'))) {
            $criteria['where']['type'] = $this->input->post('type');
        }
        if ($this->input->post('group') && strlen(trim($this->input->post('group')))) {
            $criteria['where']['group'] = $this->input->post('group');
        }
        if ($this->input->post('message') && strlen(trim($this->input->post('message')))) {
            $criteria['like']['message'] = $this->input->post('message');
        }

        //var_dump($criteria);
        $log_data = logger::i()->get_log_data($start_index, $num_records, $criteria);
        $data['aaData'] = $log_data['data'];
        $data['iTotalRecords'] = $log_data['count'];
        $data['iTotalDisplayRecords'] = $log_data['count'];
        $data['dir'] = 'asc';

        echo $this->json->encode($data);
        die();
    }

    public function delete_log(){
        $criteria = array();
        if ($this->input->post('module_name') && strlen($this->input->post('module_name'))) {
            $criteria['where']['module_name'] = $this->input->post('module_name');
        }
        if ($this->input->post('type') && strlen($this->input->post('type'))) {
            $criteria['where']['type'] = $this->input->post('type');
        }
        if ($this->input->post('group') && strlen(trim($this->input->post('group')))) {
            $criteria['where']['group'] = $this->input->post('group');
        }
        if ($this->input->post('message') && strlen(trim($this->input->post('message')))) {
            $criteria['like']['message'] = $this->input->post('message');
        }
        $total = logger::i()->clear_where($criteria);
        die($total);
    }

}

